<%@ page contentType="text/html; charset=UTF-8" language="java"%>
<%@ taglib prefix="limits" uri="/WEB-INF/tld/limits.tld"%>
<%@ page import="com.hzqy.commons.utils.ConstantUtils" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>投票内容</title>
<link rel="stylesheet" type="text/css"	href="../static/js/themes/defalut.css">
<link rel="stylesheet" type="text/css"	href="../static/js/themes/public.css">
<link rel="stylesheet" type="text/css"	href="../static/js/themes/ddspstyle.css">
<link rel="stylesheet" type="text/css"	href="../static/js/themes/default/easyui.css">
<link rel="stylesheet" type="text/css"	href="../static/js/themes/icon.css">
<link rel="stylesheet" type="text/css"	href="../static/js/WdatePicker/skin/WdatePicker.css">
<script type="text/javascript" src="../static/js/jquery.min.js"></script>
<script type="text/javascript" src="../static/js/jquery.easyui.min.js"></script>
<script type="text/javascript" src="../static/js/locale/easyui-lang-zh_CN.js"></script>
<script type="text/javascript" src="../static/js/index.js"></script>
<script type="text/javascript" src="../static/js/WdatePicker/WdatePicker.js"></script>
<%
	int f_catalog_id = 0;
	String para = request.getParameter("f_catalog_id");
	if(para != null)
		f_catalog_id = Integer.valueOf(para);
	String catalogIds = request.getParameter("ids");
%>
<%
String programatype =request.getParameter("f_catalog_programatype");
int f_catalog_programatype = 1;
if(programatype != null)
	f_catalog_programatype = Integer.valueOf(programatype);
String []nonceObj=ConstantUtils.getNonceObject();
%>
<script type="text/javascript">
		var f_catalog_id = <%=f_catalog_id%>;
		var catalogIds = '<%=catalogIds%>';
		var queryParams;
		var contentid;
		var f_cc_id;
		function EasyuiDatagrid() {
			$("#easyui-datagrid").datagrid({
				url: 'vote_bind.do',
				nowrap: true,
				striped: true,
				border: false,
				fit: true,
				rownumbers:true,
				queryParams: getGueryParams(),
				columns: [[
					{field:'ck',checkbox:true},
					{field:'f_cc_searchname',title:'参赛编号',align:'center',width:70},
					{field:'f_cc_name',title:'参赛选手姓名',align:'center',width:100},
					{field:'f_cc_obligate3',title:'年龄',align:'center',width:50},
					{field:'f_csvt_activityid',title:'活动编号',align:'center',width:100},
					{field:'f_cc_obligate2',title:'预留字段2',align:'center',width:80},
					{field:'f_cc_obligate1',title:'预留字段1',align:'center',width:80},
					{field:'f_csvt_votecount',title:'总票数',align:'center',width:50,
						formatter:function(value,row,index){
							f_csvt_votecount = row.f_csvt_votecount
							if(f_csvt_votecount == undefined){
								f_csvt_votecount=0;
							}
							return  '<a class="easyui-linkbutton l-btn l-btn-plain" iconCls="icon-ok" href="javascript:void(0);" plain="true" onclick="go_info(\''+row.f_cc_id+'\');" ><span>'+f_csvt_votecount+'</span></a>';
						}
					},
					{field:'f_catalog_starttime',title:'参赛时间',align:'center',width:150,
						formatter:function(value,row,index) {
							var str = "";
							if(value!=null)
								str = value.substring(0,19);
							return str;
						}	
					},
					{field:'f_catalog_endtime',title:'结束时间',align:'center',width:150,
						formatter:function(value,row,index) {
							var str = "";
							if(value!=null)
								str = value.substring(0,19);
							return str;
						}	
					},
					{field:'f_cc_type',title:'操作',align:'center',width:200,
						formatter:function(value,row,index){
					    	return '<a class="easyui-linkbutton l-btn l-btn-plain" iconCls="icon-ok" href="javascript:void(0);" plain="true" onclick="insertVoteCount(\''+row.f_csvt_contentid+'\',\''+row.f_cc_id+'\')" ><span class="l-btn-left"><span class="l-btn-text icon-remove l-btn-icon-left">增加</span></span></a>';
				    	}
					}
				]],
				singleSelect:false,
				pagination:true,
				pageList:[10,20,30,40,50,1000],
				pageSize:10,
				toolbar: '#toolbar',
				
				onExpandRow: function(index,row){
				
				},
				onSelect: function(rowIndex,rowData) {
					
				},
				onUnselect: function(rowIndex,rowData) {
					
				},
				onCheckAll: function(rowIndex,rowData) {
					
				},
				onUncheckAll: function(rowIndex,rowData) {
				
				},
				onLoadSuccess: function(data) {
					if(data.total==-1) {
						$.messager.defaults={ok:"确定",cancel:"取消"};
						$.messager.confirm('提示', '用户尚未登录,请登录', function(r){
						if (r){
						    window.parent.location.href='/login.do';
						    return false;
						}});
					}
				}
			});
		}
	
		function getGueryParams(){
			return {
				f_cc_searchname:$("#f_cc_searchname").val(),
				f_cc_name:$("#f_cc_name").val(),
				f_cc_obligate2:$("#f_cc_obligate2").val(),
				f_cc_obligate1:$("#f_cc_obligate1").val(),
				f_catalog_starttime:$("#f_catalog_starttime").val(),
				f_catalog_endtime:$("#f_catalog_endtime").val(),
				f_csvt_activityid:$("#f_csvt_activityid").val(), 
				min_num:$("#min_num").val(),
				max_num:$("#max_num").val(),
				f_catalog_id:f_catalog_id,
				catalogIds:catalogIds
			};
		}
		
		$(function(){
			$.ajax({
				url:"../pms/org_list.do",
				success:function(data) {
					data = JSON.parse(data);
					var str = "";
					for(var i=0;i<data.length;i++) {
						str+='<option value="'+data[i].id+'">'+data[i].name+'</option>';
					}
					$("#f_cc_companyid").append(str);
				}
			});
			$("#f_ccc_catalogid").val(f_catalog_id);
			new EasyuiDatagrid();
			gotoSearch = function(){
				$("#easyui-datagrid").datagrid('reload',getGueryParams());
			};
			gotoSearch($('#easyui-treegrid'));
			unbind = function(id){
				$.messager.confirm('确定取消分类','确定取消分类么?',function(r){
					if(r){
						app_ajax('delete_bind.do?f_ccc_contentid='+id+'&f_ccc_catalogid='+f_catalog_id+"&stime=<%=nonceObj[0]%>&sign=<%=nonceObj[1]%>",
						'',
						function(msg){
							if(msg.success) {
								alert("取消分类成功!");
								if (checkAjaxRequestValidity(msg)) {
									gotoSearch($('#easyui-treegrid'));
								}
								window.location.reload();
							} else {
								alert("取消分类异常，请联系管理员");
								if($.isFunction(window.showMessager)){
									window.showMessager(msg.resultTitle,msg.result);
								}
							}
						}
						);
					}
				});
			};
			
			bind = function(id){
				app_ajax('../content/insert_bind.do?f_ccc_contentid='+id+'&f_ccc_catalogid='+f_catalog_id+"&stime=<%=nonceObj[0]%>&sign=<%=nonceObj[1]%>",
						'',
						function(msg){
							if(msg.success) {
								alert("分类成功!");
								if (checkAjaxRequestValidity(msg)) {
									gotoSearch($('#easyui-treegrid'));
								}
								window.location.reload();
							} else {
								alert(msg.result + 'flag=' + msg.flag);
								if($.isFunction(window.showMessager)){
									window.showMessager(msg.resultTitle,msg.result);
								}
							}
						}
						);
			};
		});
		
		function SubgridTabOnSelect(title,index){
			setTimeout(function(){
				$("#easyui-datagrid").datagrid('fixDetailRowHeight',index);
			},300);
			setTimeout(function(){
				$("#easyui-datagrid").datagrid('fixDetailRowHeight',index);
			},3000);
	    }
		
		function load(){
			$(".datagrid-row-expander datagrid-row-expand").attr("display","none"); 
		}
		function go_info(id){
			openDialog($("#dlg"),'vote_info.jsp?f_cc_id='+id);
		}
		
		function _resert(){
			$("#f_cc_name").val("");
			$("#f_cc_status").val("");
		}
		
		function onpress(){
			var event=arguments.callee.caller.arguments[0]||window.event;//消除浏览器差异
	   		  	if (event.keyCode == 13){  
	      			gotoSearch($('#easyui-treegrid'));
	    		}
		}
		
		function change_vote_count() { //activityid
			var changeData = $('#change_votecount').textbox('getValue');
			var activityid = $('#activityid').textbox('getValue');
			var url="";
			//if(contentid!='undefined'){
				url="change_vote_count.do?changeData="+changeData+"&contentid="+f_cc_id+"&activityid="+activityid;
			//}else {
			//	url="insert_vote.do?f_csvt_votecount="+changeData+"&f_csvt_contentid="+f_cc_id+"&activityid="+activityid;
			//}
			$.ajax({
				url:url,
				success:function(msg){
					msg = JSON.parse(msg);
					if(msg.success) {
						alert("增加总数成功!");
						if (checkAjaxRequestValidity(msg)) {
							gotoSearch($('#easyui-treegrid'));
						}
						window.location.reload();
					} else {
						alert("增加总数异常，请联系管理员");
						if($.isFunction(window.showMessager)){
							window.showMessager(msg.resultTitle,msg.result);
						}
					}
				}
			});
		}
		
		
		function batchBind() {
			var selections = $('#easyui-datagrid').datagrid('getSelections');//返回所有被选中的行
			if(selections.length==0) {
				alert("请至少选择一行数据");
				return false;
			}
			var ids=[];
			for(var i=0;i<selections.length;i++) {
				var id = selections[i].f_cc_id;
				ids.push(id);
			}
			$.ajax({
				url:"../content/batch_bind.do?ids="+ids+"&f_ccc_catalogid="+f_catalog_id+"&stime=<%=nonceObj[0]%>&sign=<%=nonceObj[1]%>",
				success:function(msg){
					msg = JSON.parse(msg);
					if(msg.success) {
						alert("批量分类成功!");
						if (checkAjaxRequestValidity(msg)) {
							gotoSearch($('#easyui-treegrid'));
						}
						window.location.reload();
					} else {
						alert("批量分类异常，请联系管理员");
						if($.isFunction(window.showMessager)){
							window.showMessager(msg.resultTitle,msg.result);
						}
					}
				}
			});
		}
		function batchUnBind() {
			var selections = $('#easyui-datagrid').datagrid('getSelections');//返回所有被选中的行
			if(selections.length==0) {
				alert("请至少选择一行数据");
				return false;
			}
			var ids=[];
			for(var i=0;i<selections.length;i++) {
				var id = selections[i].f_cc_id;
				ids.push(id);
			}
			$.ajax({
				url:"../content/batch_unbind.do?ids="+ids+"&f_ccc_catalogid="+f_catalog_id+"&stime=<%=nonceObj[0]%>&sign=<%=nonceObj[1]%>",
				success:function(msg){
					msg = JSON.parse(msg);
					if(msg.success) {
						alert("批量取消分类成功!");
						if (checkAjaxRequestValidity(msg)) {
							gotoSearch($('#easyui-treegrid'));
						}
						window.location.reload();
					} else {
						alert("批量取消分类异常，请联系管理员");
						if($.isFunction(window.showMessager)){
							window.showMessager(msg.resultTitle,msg.result);
						}
					}
				}
			});
		}
		
		function insertVoteCount(cid,sid){
			$('#vote').window('open');
			contentid=cid;
			f_cc_id=sid;
		}
		function exportExcel(){
			var f_cc_searchname=$("#f_cc_searchname").val();
			var f_cc_name=$("#f_cc_name").val();
			var f_cc_obligate2=$("#f_cc_obligate2").val();
			var f_cc_obligate1=$("#f_cc_obligate1").val();
			var f_catalog_starttime=$("#f_catalog_starttime").val();
			var f_catalog_endtime=$("#f_catalog_endtime").val();
			var f_csvt_activityid=$("#f_csvt_activityid").val(); 
			var min_num=$("#min_num").val();
			var max_num=$("#max_num").val();
			//var f_catalog_id=f_catalog_id;
			//var catalogIds=catalogIds;
		    var url="../content/vote_bind_excel.do?f_cc_searchname="+f_cc_searchname+"&f_cc_name="+f_cc_name+"&f_cc_obligate2="+f_cc_obligate2+"&f_cc_obligate1="+f_cc_obligate1+"&f_catalog_starttime="+f_catalog_starttime+"&f_catalog_endtime="+f_catalog_endtime+"&f_csvt_activityid="+f_csvt_activityid+"&min_num="+min_num+"&max_num="+max_num+"&f_catalog_id="+f_catalog_id+"&catalogIds="+catalogIds;
			window.open(url);
		}
	</script>
</head>
<body onload="load();">
	<table id="easyui-datagrid" title="已分类列表"></table>
	<div id="toolbar" class="easyui_datagrid_toolbar" style="">
		<div class="easyuiSearch">
			<form onsubmit="return false;" method="post">
				<input type="hidden" id="f_ccc_catalogid" name="f_ccc_catalogid" value="" />
				<table cellspacing="0" cellpadding="0" width="90%">
					<tr>
						<td align="right" width="10%">参赛编号：</td>
						<td align="left" width="5%">
							<input name="f_cc_searchname"	id="f_cc_searchname" style="width: 80px;" onkeydown="onpress();" />
						</td>
						<td align="right" width="15%">参赛选手姓名：</td>
						<td align="left" width="10%">
							<input name="f_cc_name"	id="f_cc_name" style="width: 70px;" onkeydown="onpress();" />
						</td>
						<td align="right" width="15%">活动编号：</td>
						<td align="left" width="10%">
							<input name="f_csvt_activityid" id="f_csvt_activityid" style="width: 70px;" onkeydown="onpress();" />
						</td>
						<td align="right" width="15%">地区：</td>
						<td align="left" width="10%">
							<input  name="f_cc_obligate2" id="f_cc_obligate2" style="width: 70px;" onkeydown="onpress();" />
						</td>
						
					</tr>
					<tr>
						<td align="right" width="10%">手机号：</td>
						<td align="left" width="5%">
							<input name="f_cc_obligate1"	id="f_cc_obligate1" style="width: 80px;" onkeydown="onpress();" />
						</td>
						<td align="right" width="15%">总票数：</td>
						<td align="left" width="10%">
							<input name="min_num"	id="min_num" style="width: 25px;" onkeydown="onpress();" />~
							<input name="max_num"	id="max_num" style="width: 25px;" onkeydown="onpress();" />
						</td>
						<td align="right" width="15%">参赛时间：</td>
						<td align="left" width="10%">
							<input name="f_catalog_starttime"	id="f_catalog_starttime"  onClick="WdatePicker()" style="width: 70px;" onkeydown="onpress();" />
						</td>
						<td align="right" width="15%">结束时间：</td>
						<td align="left" width="10%">
							<input name="f_catalog_endtime"	id="f_catalog_endtime" style="width: 70px;" onClick="WdatePicker()" onkeydown="onpress();" />
						</td>
						<td align="left" width="15%">
								<a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'icon-search', plain:true" onclick="gotoSearch($('#easyui-datagrid'))">查询</a>
						</td>
						<td align="left" width="15%">
                         <a href="javascript:void(0);" style="width: 100px;" class="easyui-linkbutton"
                            data-options="iconCls:'icon-save', plain:true"
                            onclick="javascript:exportExcel()">导出excel</a>
                     </td>
					</tr>
				</table>
			</form>
		</div>
		<div style="margin-bottom: 5px">
			<!-- <a href="javascript:void(0)" class="easyui-linkbutton" onclick="delete();" iconCls="icon-cut" plain="true">删除</a>  -->
		</div>
	</div>
	
	<div id="dlg" class="easyui-dialog"
		style="width: 780px; height: 470px; padding-top: 0px;"
		data-options="title:'投票流水管理', iconCls:'icon-save',modal:true,closed:true,buttons:'#dlg_buttons'">
		<iframe scrolling="auto" frameborder="0"
			style="width: 100%; height: 99%;"></iframe>
	</div>
	
	<div id="vote" class="easyui-window" closed="true" modal="true" iconCls="icon-save" style="width:240px; height: 240px; left: 50%px;top: 30%;" title="票数入录">
		<div class="easyui-layout" fit="true">
			<div region="center" border="true">
				<div>
					<div style="margin-bottom:20px">
						<div>请输入活动编号:</div>
						<input class="easyui-textbox" type="text" name="activityid" id="activityid" style="width: 98%;" onkeydown="onpress();" data-options="required:true,missingMessage:'不能为空'"/>
					</div>
					<div style="margin-bottom:20px">
						<div>请输入票数:</div>
						<input class="easyui-textbox" type="text" name="change_votecount" id="change_votecount" style="width: 98%;" onkeydown="onpress();" data-options="required:true,missingMessage:'不能为空'"/>
					</div>
					<div>
						<a href="javascript:void(0);" class="easyui-linkbutton" iconCls="icon-ok" style="width:98%;height:18px"  onclick="change_vote_count()">提交</a>
					</div>
				</div>
			</div>
		</div>
	</div>
	
	
</body>
</html>